//
//  YHVisitorViewController.swift
//  YHWeibo
//
//  Created by yuhao.mac on 16/6/25.
//  Copyright © 2016年 yuhao.mac. All rights reserved.
//

import UIKit

class YHVisitorViewController: UITableViewController {
    
    //标示用户是否登录
    let isLogin:Bool = YHUserAccountTools.sharedTools.isLogin
    
    //访客视图对象
    var visitorView:YHVisitorView?
    
    override func loadView() {
        if isLogin{
            super.loadView()
        }else{
            setupVisitorView()
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    //设置访客视图
    private func setupVisitorView(){
        
        setupNav()
        visitorView = YHVisitorView()
        visitorView?.closure = {[weak self] in
            self?.loginClick()
        }
        
        view = visitorView
    }
   
    
    private func setupNav(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "loginClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "loginClick")
    }
    
    @objc private func loginClick(){
        
        let oauthVc = YHOAuthViewController()
        let navVc = UINavigationController(rootViewController: oauthVc)
        
        presentViewController(navVc, animated: true, completion: nil)
    }
}
